# coding=utf-8
import os
import uuid

# 文件分割线
SPLIT_LINE = "/"


def get_suffix_name(path):
    # 获取文件后缀名
    index = path.rfind(".")
    return path[index:]


def get_grand_dir(path):
    # 获取文件的祖父文件夹
    return os.path.dirname(os.path.dirname(path))


def get_uuid_32():
    # 获取32位uuid
    return "".join(str(uuid.uuid4()).split("-"))


def get_bro_dir(path):
    # 生成一个新的兄弟文件夹
    grand = get_grand_dir(path)
    dir_id = get_uuid_32()
    new_path = grand + SPLIT_LINE + dir_id
    os.makedirs(new_path)
    return new_path


def get_temp_shp_path(path):
    # 生成一个新的shp路径
    dir_path = get_bro_dir(path)
    return dir_path + SPLIT_LINE + get_uuid_32() + ".shp"


def get_temp_dbf_path(path):
    # 生成一个新的dbf路径
    dir_path = get_bro_dir(path)
    return dir_path + SPLIT_LINE + get_uuid_32() + ".dbf"

def get_temp_raster_path(path):
    # 生成一个新的栅格路径
    dir_path = get_bro_dir(path)
    return dir_path + SPLIT_LINE + get_uuid_32() + ".tif"


def get_temp_same_type_path(path):
    # 生成一个新的与源文件同类型路径
    dir_path = get_bro_dir(path)
    suffix_name = get_suffix_name(path)
    return dir_path + SPLIT_LINE + get_uuid_32() + suffix_name
